package com.spring.demo12.eg5;

import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 2.面相@EventListener注解方式来简化事件监听器的实现
 * @author vhans
 */
@Component
public class UserRegisterListener {
    // 通过 @EventListener 注解的方式来创建一个监听器
    // spring中处理@EventListener注解源码位于方法: org.springframework.context.event.EventListenerMethodProcessor#afterSingletonsInstantiated
    @EventListener
    @Order(1) // 通过@Order来指定优先级
    public void sendMail(UserRegisterEvent event) {
        System.out.printf("给用户「%s」发送注册成功的邮件\n", event.getName());
    }

    @EventListener
    @Order(2)
    public void sendDiscounts(UserRegisterEvent event) {
        System.out.printf("给用户『%s』发送优惠券\n", event.getName());
    }
}
